package com.cici.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cici.body.UserCreateBody;
import com.cici.entity.User;
import com.cici.exception.ExceptionEnumImpl;
import com.cici.exception.common.RestBadRequestException;
import com.cici.mapper.UserMapper;
import com.cici.service.IUserService;
import com.cici.tools.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User create(UserCreateBody body) {
        User user = new User();
        BeanUtils.copy(body,user);
        log.info("创建流水");
        if (userMapper.insert(user)<1){
            throw new RestBadRequestException(ExceptionEnumImpl.CREATE_ERROR, "充值咋豆失败");
        }
        return userMapper.selectById(body.getId());
    }
}
